<?php

namespace Wulian\Controller;

use Common\Controller\AdminbaseController;

class AdminDownloadController extends AdminbaseController {

    protected $m_download;
    public $all_type = array(
        "flow_member"=>"流量池成员",   //流量池成员列表
        "flow_month"=>"卡流量使用量",
        "card_status"=>"UIM卡状态",
        "card_merchant"=>"商户卡流量",
        "import_history"=>"卡导入历史",
        "active_history"=>"激活历史",
        "card_disabled"=>"停机保号管理",
        "card_disabled_history"=>"停复机历史",
        "order"=>"订单列表",
    );
    function _initialize() {
        parent::_initialize();
        $this->m_download = M("WlDownload");
    }

    /**
     * 列表页
     */
    public function index(){
        $download_type = I("download_type");
        $download_status = I("download_status");

        $where = array("is_del"=>0);
        if(!empty($download_type)){
            $where["download_type"] = $download_type;
        }
        if(!empty($download_status)){
            $download_status =  $download_status==-1?0:$download_status;
            $where["download_status"] = $download_status;
        }
        $count=$this->m_download->where($where)->count();
        $page = $this->page($count, 15);
        $list = $this->m_download->where($where)
            ->order("create_time DESC")
            ->limit($page->firstRow , $page->listRows)
            ->select();
        foreach($list AS &$litem){
            $litem["type_name"] = $this->all_type[$litem["download_type"]];
        }

        $this->assign("download_status",I("download_status"));
        $this->assign("page", $page->show('Admin'));
        $this->assign("list",$list);
        $this->assign("all_type",$this->all_type);
        $this->assign("download_type",$download_type);
        $this->display();
    }



    // 删除
    public function delete(){
        if(isset($_GET['id'])){
            $id = I("get.id",0,'intval');
            if ($this->m_download->where(array('download_id'=>$id))->save(array("is_del"=>1)) !==false) {
                $this->success("删除成功！");
            } else {
                $this->error("删除失败！");
            }
        }else{
            $this->error("参数有误！");
        }

    }

}